<template>
  <div>
    <el-dialog title="新增" :visible="isShowAddDialog" width="35%" @close="dialogClose">
      <el-form ref="addForm" :model="ruleForm" :rules="rules" label-width="100px">
        <el-form-item label="添加类型">
          <el-radio v-model="radio" label="0" @change="selectType">常用语类型</el-radio>
          <el-radio v-model="radio" label="1" @change="selectType">业务类型</el-radio>
        </el-form-item>
        <el-form-item :label="typelabel" prop="type">
          <el-select v-if="radio=='0'" v-model="ruleForm.type">
            <el-option v-for="item in CyyTypeOptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
          <el-select v-if="radio=='1'" v-model="ruleForm.type">
            <el-option v-for="item in ywOptions" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="namelabel" prop="name">
          <el-input v-model="ruleForm.name" placeholder="常用语"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitData()" class="pull-right margin-l-25">确定
          </el-button>
          <el-button @click="dialogClose" class="pull-right">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { addCyy } from "@/api/evaluation/word";
import { findByName } from "@/api/systemManage/dataDictionary";
export default {
  //接受父组件
  props: {
    isShowAddDialog: {
      type: Boolean,
    },
  },

  data () {
    return {
      radio: '0',
      CyyTypeOptions: [],
      ywOptions:[],
      typelabel:'常用语类型',
      namelabel:'常用语',
      ruleForm: {
        name: "",
        type: "",
      },
      rules: {
        name: [
          {
            required: true,
            message: "请输入常用语名称",
            trigger: "change,blur",
          },
        ],
        type: [
          {
            required: true,
            message: "请选择常用语类型",
            trigger: "change,blur",
          },
        ],
      },
    };
  },
  methods: {
    dialogClose () {
      this.$emit("dialogClose");
    },
    submitData () {
      this.$refs.addForm.validate((valid) => {
        if (!valid) {
          return;
        } else {
          this.ruleForm.companyId = 2;
          addCyy(this.ruleForm).then((res) => {
            this.$emit("close");
            this.$emit("dialogClose");
          });
        }
      });
    },
    selectType(){
      if(this.radio=='0'){
        this.typelabel='常用语类型'
        this.namelabel='常用语'
      }else{
        this.typelabel='业务类型'
        this.namelabel='评估目的'
      }
    },
    getOption () {
      findByName("input=" + "常用语类型").then((res) => {
        for (var i = 0; i < res.data.length; i++) {
          if(res.data[i].dictName=='常用语类型')
          this.CyyTypeOptions.push({
            label: res.data[i].dictValue,
            value: res.data[i].dictValue,
          });
        }
      });
      findByName("input=" + "业务类型").then((res) => {
        for (var i = 0; i < res.data.length; i++) {
          if(res.data[i].dictName=='业务类型')
          this.ywOptions.push({
            label: res.data[i].dictValue,
            value: res.data[i].dictValue,
          });
        }
      });
    },
  },
  mounted () {
    this.getOption();
  },
};
</script>

<style lang="less" scoped>

</style>
